package com.water.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.water.entity.*;
import com.water.service.RdChangevalueService;
import com.water.service.UsUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (RdChangevalue)表控制层
 *
 * @author 小博
 * @since 2020-12-15 10:03:38
 */
@Controller
@RequestMapping("rdchangev")
public class RdChangevalueController {
    /**
     * 服务对象
     */
    @Resource
    private RdChangevalueService rdChangevalueService;
    @Resource
    private UsUserService usUserService;

    /**
     * 跳转到底码修正记录
     * @return
     */
    @RequestMapping("/rd_reportCPreAmount")
    public String rd_reportCPreAmount() {
        return "./rd/rd_reportCPreAmount";
    }

    /**
     * 跳转到水表周检报表
     * @param model
     * @param usUser
     * @param syMetertype
     * @param usMeter
     * @return
     */
    @RequestMapping("/rd_reportMeterCheck")
    public String rd_reportMeterCheck(Model model, UsUser usUser, SyMetertype syMetertype, UsMeter usMeter) {
        Page page = PageHelper.startPage(1, 7);
        List<Map<String, Object>> maps = usUserService.queryWater();
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages", page.getPages());//总页数
        map.put("pagenum", page.getPageNum());//Limit起始位
        model.addAttribute("lists", maps);
        model.addAttribute("page", map);
        return "./rd/rd_reportMeterCheck";
    }

    /**
     * 分页
     *
     * @return
     */
    @RequestMapping("/start")
    public String pageorder(Model model, UsUser usUser, @RequestParam("stat") int stat, @RequestParam("type") String type) {
        System.out.println(usUser);
        Page page = PageHelper.startPage(stat, 7);
        List<Map<String, Object>> maps = usUserService.queryWater();
        Map<String, Object> map = new HashMap<>();
        map.put("totalPages", page.getPages());//总条数
        map.put("pages", page.getPages());//总页数
        map.put("pagenum", page.getPageNum());//Limit起始位
        model.addAttribute("lists", maps);
        model.addAttribute("page", map);
        if (type.equals("meter")) {
            return "rd/rd_reportMeterCheck";
        }
        return "error";
    }
}